import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(TextApp());

///应用的根布局
class TextApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ///构建Materia Desin 风格的应用程序
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      //默认的首页面
      home: NavaHomePage4(),
    );
  }
}

///使用 Scaffold ，在其提供的 bottomNavigationBar 的属性中 传入 BottomNavigationBar，
///然后 items 设置BottomNavigationBarItem 类型的数组，再按需设定其它一些属性，
///提供的可配置属性也基本能满足常规 app 的需求。
///通过 BottomNavigationBar 组件来实现底部导航栏还是很方便的
class NavaHomePage4 extends StatefulWidget {
  const NavaHomePage4({super.key});

  @override
  _NavaHomePage4State createState() => _NavaHomePage4State();
}

class _NavaHomePage4State extends State<NavaHomePage4> {
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      tabBar: CupertinoTabBar(
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: '首页'),
          BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.conversation_bubble), label: '消息'),
          BottomNavigationBarItem(
              icon: Icon(CupertinoIcons.profile_circled), label: '我的'),
        ],
      ),
      tabBuilder: (BuildContext context, int index) {
        return CupertinoTabView(
          builder: (BuildContext context) {
            return CupertinoPageScaffold(
              navigationBar: CupertinoNavigationBar(
                middle: Text('Page 1 of tab $index'),
              ),
              child: Material(child: buidPage(),), // 这里有省略一些代码
            );
          },
        );
      },
    );
  }

  int _selectedIndex = 0;

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  buidPage() {
    if (_selectedIndex == 0) {
      return Text("页面一");
    }

    if (_selectedIndex == 2) {
      return Text("页面二");
    }

    if (_selectedIndex == 3) {
      return Text("页面三");
    }

    return Text("页面四");
  }
}
